package main

import (
	"fmt"
)

func evaltwonumber(a, b int, op string) int {
	/**
	go的switch 会自动break，除非使用fallthrough
	*/
	var result int
	switch op {
	case "+":
		result = a + b
	case "-":
		result = a - b
	case "*":
		result = a * b
	case "/":
		result = a / b
	default:
		panic("unsuportted operator:" + op)
	}
	return result
}

func grade(score int) string {
	/**
	switch不用break，除非fallthrough
	switch后边可以没有表达式，直接跟条件，这是非常好用的
	*/
	g := ""
	switch {

	case score < 60:
		g = "F"
	case score < 80:
		g = "C"
	case score < 90:
		g = "B"
	case score <= 100:
		g = "A"
	case score < 10 || score > 100:
		fallthrough
	default:
		panic(fmt.Sprintf("Wrong score:%d", score))
	}
	return g
}

func main() {
	const filename = "abc.txt"
	//contents, err := ioutil.ReadFile(filename)
	//if err != nil {
	//	fmt.Println(err)
	//} else {
	//	fmt.Printf("%s\n", contents)
	//}
	// go语言if可以像其他语言的for一样写
	/*if contents, err := ioutil.ReadFile(filename); err != nil {
		fmt.Println(err)
	} else {
		a := fmt.Sprintf("%s\n", contents)
		fmt.Println(a)
	}*/
	/**
	if的条件里可以赋值
	if的条件里赋值的变量作用域就在这个if语句block里
	*/

	fmt.Println(
		grade(0),
		grade(59),
		grade(60),
		grade(62),
		grade(82),
		grade(99),
		grade(100),
		grade(101),
		grade(-3),
	)

}
